package com.mmall.concurrency;

import com.mmall.concurrency.example.threadLocal.RequestHolders;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpRequest;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * <p>Descriptions...
 *
 * @author Diamon.Cheng
 * @date 2019/12/2.
 */
@Slf4j
public class HttpFilters implements Filter {
    
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    
    }
    
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
    
    
        HttpServletRequest   requests =  (HttpServletRequest) servletRequest;
        log.info("do filter ,{},{}",Thread.currentThread().getId(),requests.getServletPath());
        RequestHolders.add(Thread.currentThread().getId());
        chain.doFilter(servletRequest, servletResponse);
    }
    
    @Override
    public void destroy() {
    
    }
}
